home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0018_Is Delphi Running?.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  2.0 KB  |  58 lines

  1.  
  2. >1.  Does anyone know how to determine if Delphi is running or not?
  3.  
  4. I cannot answer the VBX question, but I have done the first one.  When
  5. Delphi is running, there are several windows open, not just Delphi.
  6. Therefore, your app should check for more than one Delphi window, making it
  7. very difficult for another app to simulate being Delphi.  For example:
  8.  
  9. function DelphiIsRunning : boolean;
  10. var
  11.   H1, H2, H3, H4 : Hwnd;
  12. const
  13.   A1 : array[0..12] of char = 'TApplication'#0;
  14.   A2 : array[0..15] of char = 'TAlignPalette'#0;
  15.   A3 : array[0..18] of char = 'TPropertyInspector'#0;
  16.   A4 : array[0..11] of char = 'TAppBuilder'#0;
  17.   T1 : array[0..6] of char = 'Delphi'#0;
  18. begin
  19.   H1 := FindWindow(A1, T1);
  20.   H2 := FindWindow(A2, nil);
  21.   H3 := FindWindow(A3, nil);
  22.   H4 := FindWindow(A4, nil);
  23.   Result := (H1 <> 0) and (H2 <> 0) and
  24.             (H3 <> 0) and (H4 <> 0);
  25. end;
  26.  
  27. initialization
  28.   if not DelphiIsRunning then
  29.   begin
  30.     AboutBox := TAboutBox.Create(nil);
  31.     AboutBox.ShowModal;
  32.     AboutBox.Free;
  33.     Halt;
  34.   end;
  35. end.
  36.  
  37. The biggest problem with this approach that I've found is that when you
  38. create a program using this code, it will run from within Delphi (which is
  39. what you want), but it will also run as a standalone app as long as Delphi
  40. is currently running.  I guess that's not too big a problem :).  This is the
  41. approach used by TurboPower Software in the Orpheus Trial-Run.  I haven't
  42. seen their code, so I don't know which window(s) they are checking for, but
  43. programs created using the Trial-Run components exhibit the behaviour
  44. created by this technique.
  45.  
  46. To see the windows an app creates so you can get the list of constants
  47. above, use WinSight.
  48.  
  49. BTW, I just thought of this.  If Delphi has a DDE or OLE interface (I don't
  50. know), you could first look for an app named Delphi then try to start a
  51. conversation with any app that matches.  If it responds properly you can
  52. run, otherwise halt.  Just an idea.  This could work for other apps that do
  53. have DDE or OLE.
  54.  
  55. Hope this helps.
  56.  
  57. -Wade Tatman
  58.